﻿using ConfExpert.Forms.Base;
using DevTeam;

using System;
namespace ConfExpert.Forms.Depo
{
    public partial class KartelaSec : XForm
    {
        public KartelaSec()
        {
            InitializeComponent();
        }

        private void KartelaSec_Load(object sender, EventArgs e)
        {
            
            gridView1.Init("GetKatalog");
            gridView1.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;
            gridView1.BestFitColumns();

            gridView1.DoubleClick += gridView1_DoubleClick;
            barButtonItem1.ItemClick += barButtonItem1_ItemClick;
        }

        void gridView1_DoubleClick(object sender, EventArgs e)
        {
            KatalogId = gridView1.GetFocusedDataRow()["KatalogId"].ToInt();

            if (KatalogId > 0)
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        public int KatalogId = 0;
        void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.EndEditing();
            KatalogId = gridView1.GetFocusedDataRow()["KatalogId"].ToInt();

            if (KatalogId == 0)
            {
                KatalogId = ExecuteScalar("InsKatalog", gridView1.GetFocusedDataRow()["Name"].ToString(), gridView1.GetFocusedDataRow()["Aciklama"].ToString()).ToInt();
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }
    }
}
